using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;

public class HomeSkinSlot : SnapScrollViewElement
{
	public Image skinImage;

	public Canvas canvas;

	public GameObject selectedObject;

	[Header("Achievement")]
	public GameObject achievementObject;

	public Text infoUnlockText;

	public GameObject progressionObject;

	public Image progressionBarImage;

	public Text progressionText;

	public GameObject bestObject;

	public Text bestText;

	private SkinParameters _currentParameters;

	private Achievement _achievement;

	private Tween _achievementPopupTween;

	public SkinParameters CurrentParameters => _currentParameters;

	public void SetParameters(SkinParameters parameters)
	{
		_currentParameters = parameters;
		skinImage.sprite = _currentParameters.skinIcon;
		skinImage.color = _currentParameters.skinColor;
	}

	public void SetAchievement(Achievement achievement)
	{
		_achievement = achievement;
		infoUnlockText.text = _achievement.GetDescription();
		progressionObject.SetActive(value: false);
		bestObject.SetActive(value: false);
		if (_achievement.hasProgression)
		{
			progressionObject.SetActive(value: true);
			progressionBarImage.fillAmount = (float)_achievement.GetCurrentState() / (float)_achievement.GetObjective();
			progressionText.text = $"{_achievement.GetCurrentState()} / {_achievement.GetObjective()}";
			progressionBarImage.color = _currentParameters.mainColor;
			progressionText.color = _currentParameters.mainColor;
		}
		else if (_achievement.hasBestScore)
		{
			bestObject.SetActive(value: true);
			bestText.text = string.Format("{0} {1}", LocalizationManager.GetTranslation("TXT_GAME_BEST").ToUpper(), _achievement.GetBest());
			bestText.color = _currentParameters.mainColor;
		}
	}

	public void SetUnlocked(bool state)
	{
		if (state)
		{
			skinImage.color = _currentParameters.skinColor;
		}
		else
		{
			skinImage.color = new Color(0.25f, 0.25f, 0.25f, 1f);
		}
	}

	public void SetZoom(bool state)
	{
		if (state)
		{
			base.transform.localScale = Vector3.one * 0.75f;
            canvas.sortingOrder = 10;
			if ((bool)_achievement && !achievementObject.activeSelf)
			{
				achievementObject.SetActive(value: true);
				_achievementPopupTween.Kill();
				_achievementPopupTween = null;
				achievementObject.transform.localScale = new Vector3(1f, 0f, 1f);
				achievementObject.transform.DOScaleY(1f, 0.2f).SetEase(Ease.OutBack);
			}
		}
		else
		{
			base.transform.localScale = Vector3.one * 0.5f;
			canvas.sortingOrder = -1;
			if (_achievementPopupTween != null)
			{
				_achievementPopupTween.Kill();
			}
			achievementObject.transform.DOKill();
			_achievementPopupTween = achievementObject.transform.DOScaleY(0f, 0.2f).SetEase(Ease.Linear).OnComplete(delegate
			{
				if ((bool)achievementObject)
				{
					achievementObject.SetActive(value: false);
				}
				_achievementPopupTween = null;
			});
		}
	}

	public void SetSelected(bool state)
	{
		if (state)
		{
			selectedObject.SetActive(value: true);
		}
		else
		{
			selectedObject.SetActive(value: false);
		}
	}
}
